package com.lijian.user.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.json.JSONObject;
import com.lijian.common.domain.R;
import com.lijian.common.util.MinioUtil;
import com.lijian.user.openfeign.client.NoteClient;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;


/**
 * @author LiJian
 * @date 2024-10-29
 */
@ApiModel(description = "上传管理接口")
@RestController
@RequestMapping("/file")
@RequiredArgsConstructor
public class FileUploadController {
    private final MinioUtil minioUtil;

    @ApiOperation("文件上传")
    @RequestMapping("/upload")
    public Dict upload(@ApiParam(value = "文件",required = true) @RequestParam(value = "file",required = true) MultipartFile multipartFile) {
        String upload  = minioUtil.upload(multipartFile);
      return  Dict.create().set("errno", 0).set("data", CollUtil.newArrayList(Dict.create().set("url", upload)));
    }
    @ApiOperation("文件下载")
    @RequestMapping("/download")
    public void download(@ApiParam(value = "文件名",required = true)@RequestParam("fileName") String fileName,@ApiParam(value = "HttpServletResponse",required = true) HttpServletResponse response) {
        minioUtil.fileDownload(fileName, false, response);
    }

}
